package myspring.resource.urlresource;

import java.io.InputStream;
import java.net.MalformedURLException;
import java.util.Iterator;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.springframework.core.io.UrlResource;

/**
 * <pre>
 *   Title: UrlResourceDemo01.java
 *   Description: 
 *   Copyright: yundaex.com Copyright (c) 2013
 *   Company: 上海韵达货运有限公司
 * </pre>
 * 
 * @author liuzhaoqing
 * @version 1.0
 * @date 2014年10月29日
 */
@SuppressWarnings("rawtypes")
public class UrlResourceHttpDemo {

	@SuppressWarnings("unused")
	public static void main(String[] args) throws Exception {
		UrlResource url = null;
		try {
			url = new UrlResource("file:chinese.xml");
			url = new UrlResource("file:target/classes/xml/spring/bean/chinese.xml");
//			url = new UrlResource("file:\\app-web\\target\\classes\\xml\\spring\\bean\\chinese.xml");
			InputStream is = url.getInputStream();
			SAXReader reader = new SAXReader();
			Document doc = reader.read(url.getURL());
			Element el = doc.getRootElement();
			List list = el.elements();
			for (Iterator it = list.iterator(); it.hasNext();) {
				System.out.println(it.next());
			}
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
		System.out.println(url.getFilename());
		System.out.println(url.getDescription());
		System.out.println(url.getFile());
		System.out.println(url.getURI());
		System.out.println(url.getURL());
		System.out.println(url.getFilename());
	}

}
